package com.bafa.front.presentationbeans;

import java.util.Date;
import java.util.HashMap;

import com.bafa.objects.Match;
import com.bafa.services.RetrieveServices;
import com.bafa.util.WebsiteUtils;

public class MatchBean implements Comparable {

	private boolean awayAdded;
    protected boolean blocked;
    protected boolean confirmed;
    protected Date date;
    private int goalsA;
    private int goalsB;
    private boolean homeAdded;
    private int ID;
	protected boolean played;
    private boolean resultDue;
    private int teamA;
    private String teamAName;
    private int teamB;
    private String teamBName;
    protected String time;
    protected boolean walkover;
    private PlayerListBean scorersA;
	private PlayerListBean scorersB;
	private int divisionId;
	public MatchBean(Match match) {
		this.date = match.getDate();
		this.ID = match.getID();
		this.teamA = match.getTeamA();
		this.teamAName = RetrieveServices.getTeam(teamA+"").getName();
		this.teamB = match.getTeamB();
		this.teamBName = RetrieveServices.getTeam(teamB+"").getName();
		this.blocked = match.isBlocked();
		this.played = match.isPlayed();
		this.walkover = match.isWalkover();
		this.confirmed = match.isConfirmed();
		this.homeAdded = match.isHomeAdded();
		this.awayAdded = match.isAwayAdded();
		this.goalsA = match.getGoalsA();
		this.goalsB = match.getGoalsB();
		this.time = match.getTime();
		this.scorersA = new PlayerListBean(match.scorersA(),match);
		this.scorersB = new PlayerListBean(match.scorersB(),match);
		this.divisionId=match.getDivision();
	}
	
	public int compareTo(Object arg0) {
		MatchBean bean = (MatchBean)arg0;
		
		if(!bean.getDate().equals(this.date)){
			return this.getDate().compareTo(bean.getDate());
		}else if(bean.getTime()!=null&&this.time!=null&&!bean.getTime().equals(this.time)){
			return this.getTime().compareTo(bean.getTime());
		}else{
			return bean.getID()- this.getID();
		}
	}



	public String dateOfMatch(){
	        if(date==null) return "";
	        return dayOfWeek()+" "+day()+" "+month()+" "+year();
	}



	public int day(){
        return date.getDate();
}



	public String dayOfWeek(){
	        return WebsiteUtils.getDayOfWeek(date.getDay());
	}



	public Date getDate() {
		return date;
	}



	public int getGoalsA() {
		return goalsA;
	}



	public int getGoalsB() {
		return goalsB;
	}



	public int getID() {
		return ID;
	}



	public int getTeamA() {
		return teamA;
	}



	public String getTeamAName() {
		return teamAName;
	}



	public int getTeamB() {
		return teamB;
	}



	public String getTeamBName() {
		return teamBName;
	}



	public String getTime() {
		return time;
	}



	public boolean isAwayAdded() {
		return awayAdded;
	}



	public boolean isBlocked() {
		return blocked;
	}



	public boolean isConfirmed() {
		return confirmed;
	}



	public boolean isHomeAdded() {
		return homeAdded;
	}



	public boolean isPlayed() {
		return played;
	}



	public boolean isResultDue() {
		return resultDue;
	}



	public boolean isWalkover() {
		return walkover;
	}



	public String month(){
	        return WebsiteUtils.getMonth(date.getMonth());
	}



	public boolean resultDue(){
	        Date today = new Date();
	        if(date!=null&&date.before(today)){
	                return !isPlayed()&&!isBlocked();
	        }else{
	                return false;
	        }
	        
	}



	public void setAwayAdded(boolean awayAdded) {
		this.awayAdded = awayAdded;
	}



	public void setBlocked(boolean blocked) {
		this.blocked = blocked;
	}



	public void setConfirmed(boolean confirmed) {
		this.confirmed = confirmed;
	}



	public void setDate(Date date) {
		this.date = date;
	}



	public void setGoalsA(int goalsA) {
		this.goalsA = goalsA;
	}



	public void setGoalsB(int goalsB) {
		this.goalsB = goalsB;
	}



	public void setHomeAdded(boolean homeAdded) {
		this.homeAdded = homeAdded;
	}



	public void setID(int id) {
		ID = id;
	}



	public void setPlayed(boolean played) {
		this.played = played;
	}



	public void setResultDue(boolean resultDue) {
		this.resultDue = resultDue;
	}



	public void setTeamA(int teamA) {
		this.teamA = teamA;
	}
	
	public void setTeamAName(String teamAName) {
		this.teamAName = teamAName;
	}

public void setTeamB(int teamB) {
	this.teamB = teamB;
}

public void setTeamBName(String teamBName) {
	this.teamBName = teamBName;
}

public void setTime(String time) {
	this.time = time;
}

public void setWalkover(boolean walkover) {
	this.walkover = walkover;
}

public int year(){
        return date.getYear()+1900;
}

public PlayerListBean getScorersA() {
	return scorersA;
}

public void setScorersA(PlayerListBean scorersA) {
	this.scorersA = scorersA;
}

public PlayerListBean getScorersB() {
	return scorersB;
}

public void setScorersB(PlayerListBean scorersB) {
	this.scorersB = scorersB;
}

public int getDivisionId() {
	return divisionId;
}

public void setDivisionId(int divisionId) {
	this.divisionId = divisionId;
}

}
